package org.yagnus.stats.samplers.discrete.withoutreplacement;

import java.util.List;

import org.yagnus.stats.samplers.discrete.ProbabilitySampler;

/**
 * 
 * @author hc.busy
 * 
 *         In the worst case, drawAll will in the worst case take time O(n^2)
 *         where n is the intial sample space size. (uniform distribution
 *         results in, on average, n^2 linked list traversals.) In that case,
 *         use UniformArraySampler which has worst case run time of O(n).
 * 
 *         FIXME: fix the len and numberSampled
 * 
 */
public class ListSampler2<BASETYPE> extends WithoutReplacementSampler<BASETYPE> {

	protected ProbabilitySampler<BASETYPE> internal;

	public int getNumberSampled() {
		return internal.getNumberSampled();
	}

	public BASETYPE take() {
		BASETYPE ret = internal.sample_wor();
		return ret;
	}

	public void addSample(BASETYPE t, double w) {
		internal.addSample_wor(t, w);
	}

	@Override
	protected void _init(List<BASETYPE> t, List<Double> weights) {
		internal = new ProbabilitySampler<BASETYPE>(t, weights);
		internal.setReplacement(false);
	}

	@Override
	public void removeSample(BASETYPE t) {
		internal.removeSample_wor(t);
	}

	public ListSampler2(List<BASETYPE> t, List<Double> weights) {
		super(t, weights);
	}

	public ListSampler2(List<BASETYPE> t) {
		super(t);
	}

	public void reset() {
		internal.reset();
	}

	@Override
	public int remaining() {
		return internal.remaining();
	}
}
